home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio.more / USeqPrint-aln.cpp < prev    next >
Text File  |  1996-07-05  |  23KB  |  844 lines

  1. // USeqPrint.aln.p 
  2. // d.g.gilbert, 1991 
  3.  
  4. /*
  5.     alignment print
  6.     
  7. */
  8.  
  9. #pragma segment AlnPrint
  10.  
  11. CONST
  12.  
  13.     kAlnPrintWindowRSRCID == 1021;
  14.  
  15. /*-----
  16.   kMaxNameWidth == 120;
  17.     kNucSpace     == 2;
  18.     kNucBorder    == 6;
  19. ____*/    
  20.  
  21.  
  22. // TAlnPrintDocument -----------------------------------------------
  23.  
  24.  
  25. pascal void TAlnPrintDocument::IAlnPrintDocument(OSType fileType, TDocument parentDoc, 
  26.                     TSeqList        aAlnList; longint startbase, nbases)
  27. VAR
  28.         Boolean        needNums;
  29.         TFile        aFile;
  30.         
  31.     pascal void CloneIt( TSequence aSeq)  
  32.         //! CloneSeqList: used also in TAlnPasteCommand; make TSeqList method !?
  33.     VAR     aRow: integer;
  34.                 longint        start1, nbase1;
  35.     {
  36.         aRow= aAlnList->GetEqualItemNo(aSeq);
  37.         aSeq= TSequence(aSeq->Clone());
  38.         FailNIL( aSeq); 
  39.                 /*!? if fail, need to back out gracefully by 
  40.                     freeing already cloned seqs, BUT !NON-Cloned ones*/
  41.         fAlnList->AtPut( aRow, aSeq);
  42.         if (needNums) {
  43.             aSeq->GetSelection( start1, nbase1);
  44.             startbase= max(startbase, start1);
  45.             nbases= min(nbases, nbase1);
  46.             }
  47.     }
  48.  
  49. {
  50.     fAlnPrintView = NULL;
  51.     fParentDoc= parentDoc;
  52.     fAlnList= aAlnList;
  53.     needNums= (nbases < 1);
  54.     if (needNums) nbases= 9999999;
  55.     aAlnList->Each(CloneIt);
  56.     fFirstBase= startBase;
  57.     fNBases= nbases;
  58.     
  59.     /*---
  60.     New(aFile);
  61.     aFile->IFile(...);
  62.     aname= parentDoc.name + '.dotplot';
  63.     vol= parentdoc.vol;
  64.     dirid= parentdoc.dirid;
  65.     err= aFile->SpecifyWithTrio( name/vol/dirid);
  66.     ----*/
  67.     aFile= NewFile(fileType, kSAppSig, kUsesDataFork, kUsesRsrcFork, !kDataOpen, !kRsrcOpen);
  68.     IFileBasedDocument(aFile, fileType);
  69.     fSavePrintInfo = FALSE; //was TRUE;
  70. }
  71.  
  72. pascal TFile TAlnPrintDocument::DoMakeFile(itsCommandNumber:CommandNumber); // override 
  73. {
  74.     DoMakeFile= NewFile(fScrapType, gApplication->fCreator, kUsesDataFork, kUsesRsrcFork, 
  75.                                                 !kDataOpen, !kRsrcOpen);
  76. }
  77.  
  78. pascal void TAlnPrintDocument::FreeData(void)
  79. {
  80.     TObject(fAlnList) = FreeListIfObject(fAlnList); //We own this list
  81. }
  82.  
  83.  
  84. pascal void TAlnPrintDocument::Free(void) // override 
  85. {
  86.     FreeData();
  87.     inherited::Free();
  88. }
  89.  
  90.  
  91. pascal void TAlnPrintDocument::Close(void) /* override */ 
  92. {
  93.         /* patches for prefwindow */        
  94.     if ((fAlnPrintView->fUseColor) && (fColorButton!=NULL)) fColorButton->fHilite= TRUE;
  95.     this->SetChangeCount(0); //so we don't always get Save? yes/no/canc dlog 
  96.     inherited::Close();
  97. }
  98.  
  99.  
  100.  
  101. pascal void TAlnPrintDocument::DoMakeViews(Boolean forPrinting) // override 
  102. VAR
  103.         aWindow    : TWindow;
  104.         minSize    : Point;
  105.         maxSize    : Point;
  106.         vSize     : Vpoint;
  107. {
  108.     aWindow = gViewServer->NewTemplateWindow(kAlnPrintWindowRSRCID, this);
  109.     FailNil(aWindow);
  110.     
  111.     fAlnPrintWind = TAlnPrintWind(aWindow);
  112.     fAlnPrintWind->IAlnPrintWind();
  113.     fAlnPrintWind->fCommonNumbers= TNumberText(aWindow->FindSubView('nPCT'));
  114.     fAlnPrintWind->fRedrawBut= TButton(aWindow->FindSubView('bRDR'));
  115.     fAlnPrintWind->fUserSelect= TButton(aWindow->FindSubView('bUsr'));
  116.     fAlnPrintWind->fUserNotSelect= TButton(aWindow->FindSubView('bNot'));
  117.     fAlnPrintWind->fUserClear= TButton(aWindow->FindSubView('bClr'));
  118.     
  119.     fAlnPrintView = TAlnPrintView(aWindow->FindSubView('PrVw'));
  120.     FailNil(fAlnPrintView);
  121.  
  122.     fAlnPrintView->fCommonNumbers= fAlnPrintWind->fCommonNumbers;
  123.     fAlnPrintView->InstallControls();
  124.     
  125.     fColorButton= TIcon(aWindow->FindSubView('iClr'));
  126.     fColorButton->fEventNumber= mColorButHit;
  127.     fMonoButton= TIcon(aWindow->FindSubView('iB&W'));
  128.     fMonoButton->fEventNumber= mMonoButHit;
  129.     fAlnPrintView->fUseColor= fColorButton->fHilite;  
  130.     fColorButton->fHilite= FALSE;
  131.     fMonoButton->fHilite= FALSE;
  132.     if (!gConfiguration.hasColorQD) {
  133.         fColorButton->ViewEnable(FALSE, kDontRedraw);
  134.         fColorButton->Show(FALSE, kDontRedraw);
  135.         fMonoButton->ViewEnable(FALSE, kDontRedraw);
  136.         fMonoButton->Show(FALSE, kDontRedraw);
  137.         fAlnPrintView->fUseColor    = FALSE;
  138.         }
  139.     
  140.     // get our damn data into view 
  141.     fAlnPrintView->AddSeqs();
  142.     fAlnPrintView->SetDrawOptions();
  143.     
  144.     // set window's resize limits so it can't become wider than the AlnPrintview's edge 
  145.     WITH aWindow->fResizeLimits){
  146.         minSize = topLeft;
  147.         maxSize = botRight;
  148.         }
  149.     WITH maxSize)h = Min( 2 + fAlnPrintView->fSize.h + kSBarSizeMinus1, h);
  150.     //-- aWindow->SetResizeLimits(minSize, maxSize); << bad ??
  151.  
  152.     //?! need to show TEView in PrintView... ?
  153.     this->ShowReverted();   
  154. }
  155.  
  156.  
  157. pascal void TAlnPrintDocument::UntitledName(Str255 VAR noName) // override 
  158. //called AFTER .Idoc and .MakeViews 
  159. {
  160.     fParentDoc->GetTitle( noName);
  161.     noName= Concat(noName,' PrettyPrint'); 
  162.  
  163.     if ((fWindowList != NULL) && (fWindowList.GetSize > 0))         
  164.         TWindow(fWindowList->First())->SetTitle(noName);
  165. }
  166.  
  167.  
  168.  
  169. pascal void TAlnPrintDocument::DoNeedDiskSpace(TFile itsFile,
  170.                                                             long VAR dataForkBytes, rsrcForkBytes)
  171. {
  172.     //)!get Print record requirements 
  173.     //- inherited::DoNeedDiskSpace(dataForkBytes, rsrcForkBytes); 
  174.     
  175.     dataForkBytes = dataForkBytes + kMacdrawHeaderSize  /*+ sizeof window pict */;
  176.     
  177.     /*-- if you really want to know pict size:
  178.     fAlnPrintView->WriteToDeskScrap(); 
  179.     len= fAlnPrintView->GivePasteData( NULL, 'PICT');
  180.     rsrcForkBytes = rsrcForkBytes + kRsrcTypeOverhead + kRsrcOverhead + sizeof(DocState);
  181.     ---*/
  182. }
  183.  
  184.  
  185. pascal void TAlnPrintDocument::DoRead(aFile:TFile; Boolean forPrinting)
  186. {
  187.     //-- inherited::DoRead(aRefNum, rsrcExists, forPrinting);)!read print info stuff
  188.     // This is a Write-Only document == PICT of output drawing, no reading... ?
  189. }
  190.  
  191.  
  192. pascal void TAlnPrintDocument::DoWrite(TFile aFile, Boolean makingCopy)
  193. VAR
  194.         longint        len, count;
  195.         hPict            : handle;
  196.         header        : packed array [1..kMacdrawHeaderSize] of char;
  197.         fi                : FailInfo;
  198.  
  199.     pascal void HdlDoWrite(OSErr error, long message)
  200.     {
  201.         if (hPict != NULL) DisposHandle( hPict);
  202.     }
  203.  
  204. {
  205.     //- inherited::DoWrite(aRefNum, makingCopy);     --)NO write print info stuff
  206.  
  207.     fAlnPrintView->WriteToDeskScrap();
  208.     
  209.     hPict= NewHandle(0);
  210.     CatchFailures(fi, HdlDoWrite);
  211.     len= fAlnPrintView->GivePasteData( hPict, 'PICT');
  212.     if ((len > 0)) {
  213.         fillchar(header, kMacdrawHeaderSize, ((char)(0)));  
  214.         count = kMacdrawHeaderSize;
  215.         FailOSErr( aFile->WriteData( &header, count));
  216.         count= len;
  217.         HLock(hPict);
  218.         FailOSErr( aFile->WriteData( ptr((*hPict)), count));
  219.         HUnlock(hPict);    
  220.         }
  221.     Success(fi);
  222.     DisposHandle( hPict);
  223. }
  224.  
  225.  
  226. // TAlnPrintWind ------------------------- 
  227.  
  228. pascal void TAlnPrintWind::IAlnPrintWind(void)
  229. {
  230.     IPrefWindow();
  231.     fWantSave= TRUE;
  232. }
  233.  
  234. pascal void TAlnPrintWind::SetPrefID(void) /* override */ 
  235. {
  236.     gPrefWindID= kAlnPrintWindowRSRCID; gPrefWindName= 'TAlnPrintWind';
  237. }
  238.  
  239. pascal void TAlnPrintWind::DoEvent(EventNumber eventNumber, 
  240.                                             TEventHandler        source; TEvent event) // override 
  241. VAR
  242.         TAlnPrintView        aAlnPrintView;
  243.  
  244.     pascal void CheckPercent(void)
  245.     {
  246.         if ((fCommonNumbers.GetValue!=aAlnPrintView->fCommonPercent)) {
  247.             aAlnPrintView->AddSeqs();
  248.             //- aAlnPrintView->ForceRedraw(); 
  249.             }
  250.     }
  251.     
  252. {
  253.     aAlnPrintView= TAlnPrintDocument(fDocument).fAlnPrintView;
  254.     //- aAlnPrintView->SetDrawOptions();
  255.  
  256.     switch (eventNumber) {
  257.         mColorButHit: {
  258.                 aAlnPrintView->fUseColor= TRUE;
  259.                 aAlnPrintView->ForceRedraw();
  260.                 }
  261.         mMonoButHit: {
  262.                 aAlnPrintView->fUseColor= FALSE;
  263.                 aAlnPrintView->ForceRedraw();
  264.                 }
  265.                                 
  266.         mButtonHit: if ((source == fRedrawBut)) {
  267.                 CheckPercent();
  268.                 aAlnPrintView->SetDrawOptions();
  269.                 aAlnPrintView->ForceRedraw();
  270.                 }                
  271.             else if ((source == fUserSelect)) {
  272.                 if (aAlnPrintView->fUserSelection=NULL) 
  273.                     aAlnPrintView->fUserSelection= NewRgn;
  274.                 FailNIL( aAlnPrintView->fUserSelection);
  275.                 UnionRgn( aAlnPrintView->fSelections, aAlnPrintView->fUserSelection, 
  276.                         aAlnPrintView->fUserSelection);
  277.                 aAlnPrintView->ForceRedraw();                
  278.                 }                
  279.             else if ((source == fUserNotSelect)) {
  280.                 if (aAlnPrintView->fUserSelection!=NULL) {
  281.                     DiffRgn( aAlnPrintView->fUserSelection, aAlnPrintView->fSelections, 
  282.                             aAlnPrintView->fUserSelection);
  283.                     aAlnPrintView->ForceRedraw();    
  284.                     }
  285.                 }
  286.             else if ((source == fUserClear)) {
  287.                 if (aAlnPrintView->fUserSelection!=NULL) {
  288.                     DisposeRgn( aAlnPrintView->fUserSelection);
  289.                     aAlnPrintView->fUserSelection= NULL;
  290.                     aAlnPrintView->ForceRedraw();                
  291.                     }
  292.                 }                
  293.             else 
  294.                 inherited::DoEvent(eventNumber,source, event); 
  295.     
  296.         otherwise
  297.             inherited::DoEvent(eventNumber,source, event); 
  298.         }
  299. }
  300.  
  301.  
  302.  
  303.  
  304. // TAlnPrintView -------------------------------------
  305.  
  306. pascal void TAlnPrintView::Free(void) // override 
  307. {
  308.     Handle(fCommonBases)= DisposeIfHandle(fCommonBases);
  309.     Handle(fFirstCommon)= DisposeIfHandle(fFirstCommon);
  310.     inherited::Free();
  311. }
  312.  
  313. pascal void TAlnPrintView::AddSeqs(void)
  314. VAR  hFirst: CharsHandle;
  315. {
  316.     Handle(fCommonBases)= DisposeIfHandle(fCommonBases);
  317.     Handle(fFirstCommon)= DisposeIfHandle(fFirstCommon);
  318.     if (fCommonNumbers == NULL) fCommonPercent= 80
  319.     else fCommonPercent= fCommonNumbers->GetValue();  
  320.     fCommonBases= fAlnList->FindCommonBases(fCommonPercent, hFirst); 
  321.     fFirstCommon= hFirst;
  322. }
  323.  
  324. pascal void TAlnPrintView::Initialize(void) // override 
  325. //called by IObject/via IView...
  326. CONST
  327.     //- kBasesPerLine == 40;
  328.     kTenSpacer     == 10;
  329.  
  330. {
  331.     inherited::Initialize();
  332.     fAlnPrintDocument = NULL;
  333.     fFirstBase= 0;  
  334.     fNbases = 0;  
  335.     fAlnList= NULL;  
  336.     fNumSeqs= 0;
  337.     
  338.     fUserSelection= NULL;
  339.     fCommonBases= NULL;
  340.     fFirstCommon= NULL;
  341.     fStyleName= NULL;
  342.     fStyleBase= NULL;
  343.     fStyleNums= NULL;
  344.     fUseColor= TRUE;
  345.     fDoUseShading= TRUE;
  346.     fDoUseMatch= FALSE;
  347.     fDoTopIndex= TRUE;
  348.     fDoLeftIndex= FALSE;
  349.     fDoRightIndex= FALSE;
  350.     fDoLeftName= TRUE;
  351.     fDoRightName= FALSE;
  352.     fBasesPerLine= kBasesPerLine;
  353.     fTenSpacer= kTenSpacer;
  354.     fNameWidth= kMaxNameWidth;
  355.     fIndexWidth= kMaxNameWidth;
  356.     fShadeStyle= kShadeInvert;
  357.     fMatchChar= '.';
  358. }
  359.  
  360. pascal void TAlnPrintView::InstallControls(void)
  361. VAR  aWindow    : TWindow;
  362. {
  363.     aWindow= GetWindow;
  364.  
  365.     fShadePop= TPopup(aWindow->FindSubView('pSHD'));
  366.     fTopIndex= TCheckBox(aWindow->FindSubView('cTop'));
  367.     fLeftIndex= TCheckBox(aWindow->FindSubView('cLft'));
  368.     fRightIndex= TCheckBox(aWindow->FindSubView('cRgt'));
  369.     fLeftName= TCheckBox(aWindow->FindSubView('nLft'));
  370.     fRightName= TCheckBox(aWindow->FindSubView('nRgt'));
  371.     fUseShade= TCheckBox(aWindow->FindSubView('shad'));
  372.     fUseMatch= TCheckBox(aWindow->FindSubView('symb'));
  373.     fMatchSym= TEditText(aWindow->FindSubView('eSym'));
  374.     
  375.     fStyleName= TDlogTextView(aWindow->FindSubView('tNam'));
  376.     fStyleBase= TDlogTextView(aWindow->FindSubView('tBas'));
  377.     fStyleNums= TDlogTextView(aWindow->FindSubView('tNum'));
  378.  
  379.     if (fStyleName!=NULL) fStyleName->SetText('Names');
  380.     if (fStyleBase!=NULL) fStyleBase->SetText('Bases');
  381.     if (fStyleNums!=NULL) fStyleNums->SetText('Index');
  382. }
  383.  
  384.  
  385. pascal void TAlnPrintView::IAlnPrintView( TAlnPrintDocument itsDocument, Boolean forClipboard)
  386. VAR
  387.         itsSize        : VPoint;
  388.         aHandler    : TStdPrintHandler;
  389.         sd                : SizeDeterminer;
  390. {
  391.     fAlnPrintDocument = TAlnPrintDocument(itsDocument);
  392.     fFirstBase= fAlnPrintDocument->fFirstBase;  
  393.     fNbases = fAlnPrintDocument->fNbases;  
  394.     fAlnList= fAlnPrintDocument->fAlnList;  
  395.     fNumSeqs= fAlnList->GetSize();
  396.     
  397.     SetVPt(itsSize, kMaxCoord, kMaxCoord);
  398.     if (forClipboard)
  399.         sd = sizeVariable
  400.     else
  401.         sd = sizeFillPages;
  402.     //- IView(itsDocument, NULL, gZeroVPt, itsSize, sd, sd); 
  403.     IGridView( itsDocument, NULL, gZeroVPt, itsSize, sd, sd, 10, 50, 20, 20, 
  404.                                                     FALSE, FALSE, 0, 0, FALSE);
  405.  
  406. #if FALSE                                        //!!! Need to handle this
  407.     if (forClipboard) fWouldMakePICTScrap = TRUE;
  408. #endif
  409.     if (!forClipboard) {
  410.         New(aHandler);
  411.         FailNil(aHandler);
  412.         aHandler->IStdPrintHandler(itsDocument, this, !kSquareDots, kFixedSize, !kFixedSize);         
  413.         }
  414. }
  415.  
  416.  
  417.  
  418. pascal void TAlnPrintView::DoPostCreate(TDocument itsDocument) // override 
  419. VAR  aHandler: TStdPrintHandler;
  420. {
  421.     inherited::DoPostCreate( itsDocument);
  422.     fAlnPrintDocument = TAlnPrintDocument(itsDocument);
  423.     fFirstBase= fAlnPrintDocument->fFirstBase;  
  424.     fNbases = fAlnPrintDocument->fNbases;  
  425.     fAlnList= fAlnPrintDocument->fAlnList;  
  426.     fNumSeqs= fAlnList->GetSize();
  427.             
  428.     New(aHandler);
  429.     FailNil(aHandler);
  430.     aHandler->IStdPrintHandler(itsDocument, this, !kSquareDots, kFixedSize, !kFixedSize);     
  431. }
  432.  
  433.  
  434.  
  435. pascal void TAlnPrintView::FindNameWidth(void)
  436. VAR    
  437.         linesPerParagraph, numLinesPerSeq,
  438.         integer        maxNameWid,fontheight, maxdeep;
  439.         GrafPtr        savePort;
  440.         nums    : Str255;
  441.         longint        lastBase;
  442.         fi        : fontInfo;
  443.         
  444.     pascal void GetNameWidth(TSequence aSeq)
  445.     VAR  aName        : Str63;
  446.     {
  447.         if (aSeq!=NULL) {
  448.             aName= aSeq->fName;
  449.             maxNameWid= max(maxNameWid, StringWidth(aName));
  450.             } 
  451.     }
  452. {
  453.     if (fStyleName == NULL) fNameStyle= gPrintNameStyle 
  454.     else fNameStyle= fStyleName->fTextStyle;
  455.     if (fStyleBase == NULL) fBaseStyle= gPrintNucStyle 
  456.     else fBaseStyle= fStyleBase->fTextStyle;
  457.     if (fStyleNums == NULL) fNumStyle= gPrintNameStyle 
  458.     else fNumStyle= fStyleNums->fTextStyle;
  459.     maxdeep= 0;
  460.     
  461.     GetPort( savePort);
  462.     SetPort( gWorkPort);
  463.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  464.     maxNameWid= 0;
  465.     fAlnList->Each(GetNameWidth);
  466.     fNameWidth= Min( maxNameWid + kNucBorder, kMaxNameWidth); 
  467.     GetFontInfo(fi);
  468.     fontheight= fi.ascent+fi.descent+fi.leading;
  469.     maxdeep= Max(maxdeep, fontheight);
  470.     
  471.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fNumStyle);  /*$POP
  472.     lastBase= fFirstBase + fNBases;
  473.     NumToString( lastBase, nums);
  474.     fIndexWidth= StringWidth(nums) + kNucBorder;
  475.     GetFontInfo(fi);
  476.     fontheight= fi.ascent+fi.descent+fi.leading;
  477.     maxdeep= Max(maxdeep, fontheight);
  478.     
  479.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fBaseStyle);  /*$POP
  480.     fBaseWidth= CharWidth('G') + kNucSpace;
  481.     GetFontInfo(fi);
  482.     fontheight= fi.ascent+fi.descent+fi.leading;
  483.     maxdeep= Max(maxdeep, fontheight);
  484.     
  485.         //fix grid size: 
  486.     DelColLast( fNumOfCols);
  487.     InsColLast( fBasesPerLine+4, fBaseWidth);
  488.     
  489.     linesPerParagraph= fNumSeqs + 2; //+ top index + bottom spacer
  490.     numLinesPerSeq= (fBasesPerLine - 1 + fNBases) / fBasesPerLine;
  491.     
  492.     DelRowLast( fNumOfRows);
  493.     InsRowLast( linesPerParagraph * numLinesPerSeq, maxDeep);
  494.     
  495.     SetPort( savePort);
  496. }
  497.  
  498.  
  499. pascal void TAlnPrintView::SetDrawOptions(void) 
  500. VAR        
  501.         integer        wid, i ;
  502.         Str255        aStr;
  503. {
  504.     FindNameWidth();
  505.  
  506.     if (fShadePop == NULL) fShadeStyle= kShadeInvert 
  507.     else fShadeStyle= fShadePop->GetCurrentItem();  
  508.  
  509.     if (fTopIndex == NULL) fDoTopIndex= TRUE else fDoTopIndex= fTopIndex->IsOn();  
  510.     if (fLeftIndex == NULL) fDoLeftIndex= FALSE else fDoLeftIndex= fLeftIndex->IsOn();  
  511.     if (fRightIndex == NULL) fDoRightIndex= FALSE else fDoRightIndex= fRightIndex->IsOn();  
  512.     if (fLeftName == NULL) fDoLeftName= FALSE else fDoLeftName= fLeftName->IsOn();  
  513.     if (fRightName == NULL) fDoRightName= FALSE else fDoRightName= fRightName->IsOn();  
  514.     
  515.     if (fDoLeftName) wid= fNameWidth else wid= 0;
  516.     this->SetColWidth( 1, 1, wid);
  517.     if (fDoLeftIndex) wid= fIndexWidth else wid= 0;
  518.     this->SetColWidth( 2, 1, wid);
  519.     
  520.     FOR i= 1 TO fBasesPerLine){
  521.         if ((i<fBasesPerLine) && (i % 10 == 0)) SetColWidth( i+2, 1, fBaseWidth+fTenSpacer)
  522.         else SetColWidth( i+2, 1, fBaseWidth);
  523.         }
  524.         
  525.     if (fDoRightIndex) wid= fIndexWidth else wid= 0;
  526.     this->SetColWidth( 2+fBasesPerLine+1, 1, wid);
  527.     if (fDoRightName) wid= fNameWidth else wid= 0;
  528.     this->SetColWidth( 2+fBasesPerLine+2, 1, wid);
  529.  
  530.     if (fUseShade == NULL) fDoUseShading= FALSE else fDoUseShading= fUseShade->IsOn();
  531.     if (fUseMatch == NULL) fDoUseMatch= FALSE else fDoUseMatch= fUseMatch->IsOn();
  532.     if (fDoUseMatch) {
  533.         fMatchSym->GetText( aStr);
  534.         fMatchChar= aStr[1];
  535.         }
  536. }
  537.  
  538.  
  539. pascal void TAlnPrintView::DrawRangeOfCells(GridCell startCell, stopCell, VRect aRect) 
  540.                     // override 
  541. {
  542.     laserLine( 2, 4); // set laserline smaller ...
  543.     //- SetDrawOptions; 
  544.  
  545.     inherited::DrawRangeOfCells( startCell, stopCell, aRect);
  546. }
  547.  
  548.  
  549.  
  550. pascal void TAlnPrintView::DrawCell(GridCell aCell, VRect aRect) // override 
  551. CONST
  552.     kFontDescent == 2;
  553.     kIndexRise == 1;
  554. VAR
  555.     longint        atBase ;
  556.     integer        linesPerParagraph ;
  557.     longint        atSeq, seqLine ;    
  558.     Boolean        doTopIndex, doSequence;
  559.     
  560.     
  561.     pascal void drawTopIndex( longint atBase)  
  562.     VAR  nums    : str255;
  563.              integer        chRight, chLeft, rowtop, ws;
  564.     {
  565.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fNumStyle);  /*$POP
  566.         chleft    = aRect.left;
  567.         chRight    = chleft + fBaseWidth; //fix for extra spacers
  568.         rowtop    = aRect.bottom-kIndexRise;  
  569.         MoveTo( chleft+kNucSpace, rowtop);
  570.         if (atBase % 10 == 4) then begin
  571.             Line(0,-1);
  572.             NumToString( atBase+1, nums);
  573.             ws= StringWidth(nums);
  574.             Move(-ws / 2, -1);
  575.             DrawString(nums);
  576.             }        else
  577.             Line(0,-2);
  578.         MoveTo( chleft, rowtop);
  579.         LineTo( chright, rowtop);
  580.     }
  581.  
  582.     pascal void drawSideIndex(longint atBase, leftBorder)
  583.     str255        VAR  nums ;
  584.     {
  585.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fNumStyle);  /*$POP
  586.         MoveTo( aRect.right-leftBorder, aRect.bottom-kFontDescent);
  587.         NumToString( atBase+1, nums);
  588.         Move( -StringWidth(nums), 0);
  589.         DrawString(nums);
  590.     }
  591.  
  592.     pascal void DrawName(integer atSeq, rightBorder, longint atBase)
  593.     VAR     aName    : Str63;
  594.                 aSeq    : TSequence;
  595.     {
  596.         aSeq= fAlnList->SeqAt( atSeq);
  597.         if (aSeq!=NULL) {
  598.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  599.             MoveTo( aRect.left+rightBorder, aRect.bottom-kFontDescent);
  600.             aName= aSeq->fName;
  601.             DrawString(aName);
  602.             } 
  603.     }
  604.  
  605.     pascal void DrawNuc(integer atSeq, longint atBase, GridCell atCell)
  606.     VAR
  607.          integer        rowbot, nucwidth, cw, rowleft;
  608.         Boolean        firstSeq, useSym, isUserShaded, isCommonBase;
  609.         hSeq        : CharsHandle;
  610.         ch            : char;
  611.         aSeq        : TSequence;
  612.         myRect    : Rect;
  613.     {
  614.         aSeq= fAlnList->SeqAt( atSeq);
  615.         if (aSeq!=NULL) {
  616.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fBaseStyle);  /*$POP
  617.             nucwidth= fBaseWidth; //aRect.right - aRect.left; 
  618.             rowleft= aRect.left;
  619.             rowbot = aRect.bottom - kFontDescent;  
  620.             VRectToRect( aRect, myRect);
  621.             myRect.right= myRect.left + fBaseWidth; //fix for extra spacers
  622.              firstSeq= (atSeq == 1);
  623.             handle(hSeq)= aSeq->fBases;
  624.             ch= (*hSeq)^[atBase];
  625.             if (ch == indelSoft) then ch= indelHard; //look better for output...
  626.             useSym= FALSE;
  627.             isCommonBase= (fCommonBases!=NULL) && (UprChar(ch) == (*fCommonBases)^[atbase]);
  628.             isUserShaded= (fUserSelection!=NULL) && (PtInRgn( atCell, fUserSelection));
  629.             
  630.             if ((fDoUseMatch) && (isCommonBase)) {
  631.                 //- if (!firstSeq) useSym= TRUE; *//*< THIS IS Bad, need fix for FirstDrawn...
  632.                 if ((fFirstCommon!=NULL) && (ORD((*fFirstCommon)^[atbase]) < atSeq)) useSym= TRUE;
  633.                 }
  634.                                 
  635.             if ((isUserShaded) || ((fDoUseShading) && (isCommonBase))) 
  636.                 switch (fShadeStyle) {
  637.                     kShadeGray25     : { RGBForeColor( gGray25); PaintRect(myRect); }
  638.                     kShadeGray75     : { RGBForeColor( gGray75); PaintRect(myRect); }
  639.                     kShadeGray50     : { RGBForeColor( gGray50); PaintRect(myRect); }
  640.                     kShadeStipple50: { RGBForeColor( gNcolor); FillRect(myRect, gray); }
  641.                     kShadeStipple75: { RGBForeColor( gNcolor); FillRect(myRect, dkGray); }
  642.                     kShadeStipple25: { RGBForeColor( gNcolor); FillRect(myRect, ltGray); }
  643.                     }
  644.  
  645.             if (fUseColor) CASE ch OF
  646.                 'A','a': RGBForeColor( gAcolor);
  647.                 'C','c': RGBForeColor( gCcolor);
  648.                 'G','g': RGBForeColor( gGcolor);
  649.                 'T','t',
  650.                 'U','u': RGBForeColor( gTcolor);
  651.                 otherwise
  652.                                  RGBForeColor( gNcolor);
  653.                 }            else
  654.                 RGBForeColor( gNcolor);
  655.             
  656.             if ((isUserShaded) || ((fDoUseShading) && (isCommonBase))) 
  657.                 switch (fShadeStyle) {
  658.                     kShadeInvert: {
  659.                         PaintRect(myRect); 
  660.                         TextMode(srcBIC);
  661.                         }
  662.                     }
  663.                                     
  664.             cw= (nucwidth - charwidth(ch)) / 2;
  665.             MoveTo( rowleft+cw, rowbot);
  666.             if (useSym) DrawChar(fMatchChar) else DrawChar(ch);
  667.             TextMode(srcOr); //? srcOr/srcCopy
  668.             }
  669.     }  
  670.  
  671. {
  672.     linesPerParagraph= fNumSeqs + 2; //+ top index + top spacer
  673.     seqLine=  (aCell.v-1) / linesPerParagraph;
  674.     atSeq     = ((aCell.v-1) % linesPerParagraph) - 1;
  675.     
  676.     if ((atSeq < 0) || (atSeq > fNumSeqs)) {
  677.         //spacer line
  678.         doTopIndex= FALSE;
  679.         doSequence= FALSE;
  680.         }    else if ((atSeq == 0)) {
  681.         doTopIndex= TRUE;
  682.         doSequence= FALSE;
  683.         }    else {
  684.         //sequence line
  685.         doTopIndex= FALSE;
  686.         doSequence= TRUE;
  687.         }
  688.  
  689.     if ((aCell.h == 1)) {
  690.         //nameleft
  691.         atBase= fFirstBase + min( fNbases, seqLine * fBasesPerLine);
  692.         if (doSequence && fDoLeftName) DrawName( atSeq, 0, atBase);
  693.         }    else if ((aCell.h == 2)) {
  694.         //indexLeft
  695.         atBase= fFirstBase + min( fNbases, seqLine * fBasesPerLine);
  696.         if (doSequence && fDoLeftIndex) DrawSideIndex( atBase, kNucBorder);
  697.         }        
  698.     else if ((aCell.h < fBasesPerLine+3)) {
  699.         //bases
  700.         atBase= (seqLine * fBasesPerLine) + aCell.h - 2;
  701.         if ((atBase <= fNBases)) {
  702.             atBase= fFirstBase - 1 + atBase;     //atbase == 0  for first 
  703.             if (doSequence) DrawNuc( atSeq, atBase, aCell)
  704.             else if (doTopIndex && fDoTopIndex) DrawTopIndex( atBase);
  705.             }
  706.         }        
  707.     else if ((aCell.h == fBasesPerLine+3)) {
  708.         //indexRight
  709.         atBase= fFirstBase - 1 + min( fNBases, (seqLine+1) * fBasesPerLine);
  710.         if (doSequence && fDoRightIndex) DrawSideIndex( atBase, 0);
  711.         }    else if ((aCell.h == fBasesPerLine+4)) {
  712.         //nameRight
  713.         atBase= fFirstBase - 1 + min( fNBases, (seqLine+1) * fBasesPerLine);
  714.         if (doSequence && fDoRightName) DrawName( atSeq, kNucBorder, atBase);
  715.         }
  716. }
  717.  
  718.  
  719.  
  720. pascal void TAlnPrintView::CalcMinFrame(VRect VAR minFrame)
  721. {
  722.     inherited::CalcMinFrame( minFrame);
  723. }
  724.  
  725.  
  726.  
  727.  
  728. pascal void TAlnPrintView::DoMenuCommand(CommandNumber aCommandNumber) // override 
  729. {
  730.     switch (aCommandNumber) {
  731.         cCopy: {
  732.                 this->WriteToDeskScrap(); 
  733.                 gClipboardMgr->CheckDeskScrap(); //! this notifies app of changed scrap 
  734.                 }
  735.         otherwise
  736.             inherited::DoMenuCommand(aCommandNumber);
  737.         }
  738. }
  739.  
  740.  
  741. /*******
  742. pascal TCommand TAlnPrintView::DoMouseCommand(Point VAR theMouse, EventInfo VAR info,
  743.                                    Point VAR hysteresis)
  744. VAR
  745.         FailInfo        fi;
  746.  
  747.     pascal void HdlInitCmdFailed(OSErr error, long message)
  748.         {
  749.         FreeIfObject(protoAlnPrint);
  750.         protoAlnPrint = NULL;
  751.         }
  752.  
  753.     {                    
  754.     DoMouseCommand = NULL;
  755.  
  756.     fClickPt = theMouse;
  757.     if (palette->fCurrAlnPrint > 0) { // draw mode
  758.         FailSpaceIsLow();                                 // Make sure we aren't low on memory 
  759.  
  760.         Deselect();
  761.  
  762.         //Clone appropriate AlnPrint
  763.  
  764.         protoAlnPrint = TAlnPrint(gAlnPrintsArray[palette->fCurrAlnPrint].Clone);
  765.         FailNil(protoAlnPrint);
  766.  
  767.         CatchFailures(fi, HdlInitCmdFailed);
  768.         // Make sure cloning the AlnPrint left us with enough memory to continue.
  769.         FailSpaceIsLow();
  770.  
  771.         New(AlnPrintSketcher);
  772.         FailNil(AlnPrintSketcher);
  773.         AlnPrintSketcher->IAlnPrintSketcher(this, protoAlnPrint, info.theOptionKey);
  774.         Success(fi);
  775.         DoMouseCommand = AlnPrintSketcher;
  776.         }            
  777.         
  778.     else {         //select mode
  779.         AlnPrintUnderMouse = NULL;
  780.         fAlnPrintDocument->EachVirtualAlnPrintDo(CheckAlnPrint);
  781.  
  782.         if (AlnPrintUnderMouse == NULL)    {        //area select
  783.             if (!info.theShiftKey)
  784.                 Deselect();
  785.             New(AlnPrintSelector);
  786.             FailNil(AlnPrintSelector);
  787.             AlnPrintSelector->IAlnPrintSelector(cMouseCommand, this);
  788.             DoMouseCommand = AlnPrintSelector;
  789.             } 
  790.  
  791.         else {                                        //AlnPrint select/move/...
  792.             if (!(AlnPrintUnderMouse->fIsSelected || info.theShiftKey))
  793.                 Deselect();
  794.  
  795.             if (info.theShiftKey) {
  796.                 AlnPrintUnderMouse->fIsSelected = !AlnPrintUnderMouse->fIsSelected;
  797.                 if (AlnPrintUnderMouse->fIsSelected)
  798.                     AlnPrintUnderMouse->Highlight(hlOff, hlOn)
  799.                 else
  800.                     AlnPrintUnderMouse->Highlight(hlOn, hlOff);
  801.                 }            else if (!AlnPrintUnderMouse->fIsSelected)
  802.                 {
  803.                 AlnPrintUnderMouse->fIsSelected = TRUE;
  804.                 DoHighlightSelection(hlOff, hlOn);
  805.                 }
  806.  
  807.             if (AlnPrintUnderMouse->fIsSelected) {
  808.                 New(AlnPrintDragger);
  809.                 FailNil(AlnPrintDragger);
  810.                 AlnPrintDragger->IAlnPrintDragger(this);
  811.                 DoMouseCommand = AlnPrintDragger;
  812.                 }
  813.             //else, fall-through, we return NULL
  814.             }     
  815.         }                     
  816. }                                        
  817. **********/
  818.  
  819.  
  820.  
  821. pascal void TAlnPrintView::DoSetupMenus(void)
  822.     {
  823.         short        i;
  824.         Boolean        anySelection;
  825.         Boolean        haveMemory;
  826.         MenuHandle        aMenuHandle;
  827.         short        item;
  828.         Str255        itemName;
  829.  
  830.  
  831.     inherited::DoSetupMenus();
  832.  
  833.     anySelection = FALSE;
  834.     haveMemory = !MemSpaceIsLow;
  835.  
  836.     Enable(cCopy, TRUE && haveMemory);
  837. /*----    
  838.     Enable(cCut, anySelection && haveMemory);
  839.     if (haveMemory) CanPaste(kPrintClipType);
  840.     Enable(cClear, anySelection);
  841. -------*/
  842. }             
  843.  
  844.